
var table = new Table();
$(document).ready(function() {
	initTable();
});


var initTable =function(){
	//表格加载的字段
    var columns = [
		    { 'data': 'id','render': function (data) {return '<input type="checkbox" data-id="' + data + '" name="">';}},
		    {'data': 'account'},
		    {'data': 'name'},
		    {'data': 'phone'},
		    {'data': 'email'},
		    {'data': 'createdate'},
		    {'data': 'lastlogin'},
		    {'data': 'id','render':function(data,type,full){return table.delBtn(data)+table.editBtn('编辑管理员',basePath+'/admin/toEditAdmin?id='+data,'1')+'<a title="删除" href="javascript:;" onclick="reset(\''+data+'\')" class="btn btn-warning radius size-MINI" style="margin-right:10px;" >重置密码</a>';}}
		  ];
	//设置URL和加载的字段
    table.setting("/admin/getAdminList","/admin/delAdmin",columns);
	//调用表格分页
    table.tablePage();
}


var reset = function(id){
	layer.confirm('确认要重置该帐号的密码吗?',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
			type:"post",
			url:basePath+"/admin/resetPass",
			data:{"id":id},
			success:function(res){
				if(res.code == "-3"){
					forwardLogin();
		    		return false;
	        	}
                if(res.code == "-5"){
                    layer.msg(res.msg,{icon:2,time:1500});
                    return false;
                }

				if(res.code=="0"){
					layer.msg('密码重置成功',{icon:1,time:1000});
				}else{
					alert('error');
				}
			}
		});
		
		
	});
}